import { defineConfig } from 'astro/config';
import tailwind from "@astrojs/tailwind";
import mdx from "@astrojs/mdx";
import react from "@astrojs/react";
import BuildSearchIndex from './src/integration/BuildSearchIndex';
import ViteWasm from 'vite-plugin-wasm';
import WikiGuideChangelogGenerate from './src/integration/WikiGuideChangelogGenerate';
import rehypeHiddenTextParser from './src/plugins/rehype/rehype-hidden-text-parser';
import { visualizer } from 'rollup-plugin-visualizer';
import GenerateTypes from './src/integration/GenerateTypes';
import BabelPolyfillSingleFile from './src/integration/BabelPolyfillSingleFile';
import serviceWorker from "astrojs-service-worker";
import sitemap from "@astrojs/sitemap";
import BuildPagefind from './src/integration/BuildPagefind';
import BuildServiceWorker from './src/integration/BuildServiceWorker';

// https://astro.build/config
export default defineConfig({
  integrations: [tailwind(), mdx({
    rehypePlugins: [rehypeHiddenTextParser]
  }), react({
    include: ['**/*']
  }), BuildPagefind(), WikiGuideChangelogGenerate(), GenerateTypes(), BabelPolyfillSingleFile(), BuildServiceWorker(), sitemap()],
  base: '/',
  site: 'http://pdc.lq0.tech',
  server: {
    host: true
  },
  vite: {
    plugins: [ViteWasm()],
    build: {
      rollupOptions: {
        logLevel: 'silent',
        plugins: [visualizer()]
      },
    },
    optimizeDeps: [
      // import on runtime
      'pagefind'
    ],
    server: {
      host: true
    },
    json: {
      stringify: true
    },
    resolve: {
      alias: [{
        find: '@/',
        replacement: 'src/'
      }, {
        find: '@content/',
        replacement: 'src/content/'
      }, {
        find: '@formula/',
        replacement: 'src/content/_componenets/formula'
      }, {
        find: '@type/',
        replacement: 'src/types'
      }, {
        find: '@markdown/',
        replacement: 'src/content/_componenets/markdown'
      }, {
        find: "pinyin",
        replacement: "node_modules/pinyin"
      }]
    }
  }
});